#include "lvos.h"
#include "thread_intf.h"
#include "log_intf.h"
#include "webcli/webcli.h"

typedef struct TagModuleInit {
    const char *moduleName;
    int32_t(*initModule)(void);
    void(*deInitModule)(void);
} ModuleInit;

ModuleInit g_moduleInit[] = {
    {"log",      log_init,         log_deinit        },
    {"lwt",      LwtModuleInit,    NULL              },
    {"webcli",   WebcliInit,      WebcliDeinit       }
};

int32_t InitAllModules(void)
{
    int32_t ret = RETURN_OK;
    for (uint32_t index = 0; index < ARRAY_LEN(g_moduleInit); ++index) {
        ret = g_moduleInit[index].initModule();
        if (ret != RETURN_OK) {
            printf("init module %s failed, ret(%d)\n", g_moduleInit[index].moduleName, ret);
            return ret;
        }
    }
    LOG_INFO("init all module success");
    return RETURN_OK;
}

void DeInitAllModules(void)
{
    for (uint32_t index = 0; index < ARRAY_LEN(g_moduleInit); ++index) {
        if (g_moduleInit[index].deInitModule != NULL) {
            g_moduleInit[index].deInitModule();
        }
    }
}
